home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Personal Computer World 2009 February
/
PCWFEB09.iso
/
Software
/
Resources
/
Chat & Communication
/
Digsby build 37
/
digsby_setup.exe
/
lib
/
gui
/
skin
/
skintree.pyo
(
.txt
)
< prev
Wrap
Python Compiled Bytecode
|
2008-10-13
|
12KB
|
397 lines
# Source Generated with Decompyle++
# File: in.pyo (Python 2.5)
from __future__ import with_statement
SKIN_FILENAME = 'skin.yaml'
VARIANT_DIR = 'Variants'
SKIN_NAME_KEY = 'name'
VARIANT_NAME_KEY = 'variant'
alternating_keys = [
'buddiespanel.backgrounds.buddy',
'filetransfers.backgrounds.normal']
FONT_MULTIPLY_KEY = 'FontPlatform'
FONT_MULTIPLY = {
'windows_mac': 4 / 3,
'mac_windows': 3 / 4 }
__metaclass__ = type
from operator import isMappingType
from util import Storage as S
from path import path
from copy import deepcopy
import syck
import sys
import os
import wx
from wx import GetTopLevelWindows, GetApp, MessageBox, StandardPaths
from traceback import print_exc
from gui.toolbox import colorfor
from types import FunctionType
from util.merge import merge, merge_keys, tolower
from util import syck_error_message, funcinfo
from gui.skin.skintransform import transform
from gui.skin import SkinException
from peak.util.plugins import Hook
from logging import getLogger
log = getLogger('skin')
info = log.info
activeTree = None
resource_paths = [
path('res').abspath(),
path('res/skins/default').abspath()]
def get(dottedpath, default = sentinel):
try:
return lookup(activeTree, dottedpath.lower().split('.'))
except (KeyError, TypeError):
if default is sentinel:
raise SkinException('not found: ' + dottedpath)
else:
return default
except:
default is sentinel
print_exc()
print >>sys.stderr, 'exception for "%s"' % dottedpath
def refresh_wx_tree():
UMenu = UMenu
import gui.uberwidgets.umenu
skip = (UMenu,)
for window in GetTopLevelWindows():
window.FrozenQuick().__enter__()
try:
_updateskin(window, skip)
finally:
pass
UMenu.CallAll(UMenu.UpdateSkin)
def _updateskin(window, skip):
try:
update = window.UpdateSkin
except AttributeError:
pass
if not isinstance(window, skip):
try:
update()
print_exc()
for c in window.Children:
_updateskin(c, skip)
def alternating(tree):
SkinList = SkinList
import gui.skin.skinobjects
for k in alternating_keys:
spath = k.split('.')
try:
val = lookup(tree, spath)
except AttributeError:
continue
if isinstance(val, list):
lookup(tree, spath[:-1])[spath[-1]] = SkinList(val)
continue
def fontplatform(finaltree):
skin = skin
import gui
platformName = platformName
import config
platform_aliases = {
'win': 'windows',
'mac': 'mac' }
fontplatform = finaltree.get(FONT_MULTIPLY_KEY.lower(), None)
fp = '%s_%s' % (fontplatform, platform_aliases.get(platformName))
factor = FONT_MULTIPLY.get(fp, 1)
log.info('new font multiply factor: %s -> %s', fp, factor)
skin.font_multiply_factor = factor
pretransforms = [
fontplatform]
posttransforms = [
alternating]
def set_active(skin, variant = None, update_gui = False, callback = None):
global activeTree
log.info('set_active(%s, %s)', skin, variant)
app = GetApp()
skin = resource_paths[0] / path('skins') / skin
if variant is not None:
variant = skin / VARIANT_DIR / variant + '.yaml'
skinpath = skin / SKIN_FILENAME
default_path = resource_paths[0] / 'skins' / 'default' / SKIN_FILENAME
paths = [
default_path]
if not skinpath.exists():
log.critical('cannot find %s (%r.exists() == False, defaulting to silverblue', skin, skinpath)
skin = resource_paths[0] / path('skins') / 'silverblue'
skinpath = skin / SKIN_FILENAME
variant = None
if default_path.abspath() != skinpath.abspath():
paths.append(skinpath)
if variant is not None and variant.exists():
paths.append(variant)
else:
log.warning('cannot find variant %s for skin %s', variant, skin)
if not update_gui and hasattr(app, 'skin') and app.skin.paths == paths:
log.info('skin did not change, returning')
log.info('loading YAML from %d path(s):\n %s', len(paths), '\n '.join(paths))
trees = get_skintrees(skin, paths)
default_tree = deepcopy(trees[0])
combined_tree = merge(*trees, **dict(keytransform = (lambda k: getattr(k, 'lower', (lambda k: k))()
)))
if not hasattr(app, 'skin'):
app.skin = S()
app.skin.update(path = skinpath.parent, paths = get_image_load_paths(paths))
for pretransform in pretransforms:
pretransform(combined_tree)
try:
finaltree = transform(combined_tree)
except Exception:
e = None
MessageBox('There was an error processing skin "%s":\n\n%s' % (skin, str(e)), 'Skin Error')
print_exc()
finaltree = transform(default_tree)
for posttransform in posttransforms:
posttransform(finaltree)
activeTree = finaltree
app.skin.update(tree = finaltree)
def done():
if update_gui:
refresh_wx_tree()
if callback is not None:
callback()
wx.CallAfter(done)
return app.skin
def list_skins():
resource_paths = sys.modules['gui.skin.skintree'].resource_paths
skins = []
for res in resource_paths:
skinrootdir = res / 'skins'
if skinrootdir.exists():
for skindir in skinrootdir.dirs():
if skindir.name.startswith('.'):
continue
rootfile = skindir / SKIN_FILENAME
if rootfile.exists() and skindir.name != 'default':
skins.append(skindesc(rootfile))
continue
return skins
def get_skintrees(skin, paths):
trees = []
for f in paths:
try:
trees.append(load_skinfile(f))
continue
except Exception:
e = None
MessageBox('There was an error loading skin "%s":\n\n%s' % (skin, str(e)), 'Skin Error')
continue
for hook in Hook('digsby.skin.load.trees'):
hook_trees = hook()
if hook_trees is not None:
trees.extend(hook_trees)
continue
None<EXCEPTION MATCH>Exception
return trees
def get_image_load_paths(paths):
image_load_paths = [ p.parent for p in paths ]
for pathhook in Hook('digsby.skin.load.skinpaths'):
hook_paths = pathhook()
if hook_paths is not None:
image_load_paths.extend(hook_paths)
continue
[]
return image_load_paths
def quick_name_lookup(p, **names):
names = dict((lambda .0: for key, name in .0:
(name.lower(), key))(names.iteritems()))
vals = { }
try:
f = _[2]
s = syck.load(f)
print type(s)
for k, name in getattr(s, ('iteritems',), (lambda : s))():
try:
k = k.lower()
except AttributeError:
continue
if k in names and isinstance(name, basestring):
vals[k] = name
if len(vals) == len(names):
break
len(vals) == len(names)
finally:
pass
return vals
def skindesc(rootfile):
rootfile = path(rootfile)
aliases = quick_name_lookup(rootfile, skin_alias = SKIN_NAME_KEY, novariant_alias = VARIANT_NAME_KEY)
variants = []
vardir = rootfile.parent / VARIANT_DIR
if vardir.exists():
for variant in vardir.files('*.yaml'):
if variant != rootfile:
valias = quick_name_lookup(variant, variant_alias = VARIANT_NAME_KEY).get('variant_alias', variant.namebase)
variants.append(S(path = variant, alias = valias))
continue
return S(name = rootfile.parent.name, alias = aliases.get(SKIN_NAME_KEY, rootfile.parent.name), novariant_alias = aliases.get(VARIANT_NAME_KEY, _('(none)')), base = rootfile, variants = variants)
def lookup(root, pathseq):
elem = root
for p in pathseq:
elem = elem[p]
return elem
def load_skinfile(filepath):
if not filepath.exists():
raise ValueError('file %s does not exist' % filepath)
return globals()['load_%s' % filepath.ext[1:]](filepath)
def load_yaml(str_or_path):
(bytes, fpath) = getcontent(str_or_path)
if isinstance(bytes, unicode):
bytes = bytes.encode('utf-8')
if not bytes:
raise SkinException('no bytes in ' + str_or_path)
content = load_yaml_content(bytes)
try:
root = syck.load(content)
except syck.error:
e = None
raise SkinException(syck_error_message(e, fpath))
return merge_keys(root)
def load_yaml_content(bytes, included_paths = None):
if included_paths is None:
included_paths = []
lines = []
for line in bytes.split('\n'):
if line.lower().startswith('include:'):
include_path = line[line.index(':') + 1:].strip()
line = load_yaml_include(include_path, included_paths)
lines.append(line)
return '\n'.join(lines)
def load_yaml_include(incpath, included_paths):
incpath = path(incpath).abspath()
if incpath not in included_paths:
bytes = load_yaml_content(incpath.bytes(), included_paths)
included_paths += [
incpath]
return bytes
else:
return ''
from util.data_importer import zipopen
from contextlib import closing
def getcontent(str_or_path):
try:
if str_or_path.exists():
return (str_or_path.bytes(), str_or_path)
try:
f = _[2]
return (f.read(), str_or_path)
finally:
pass
except AttributeError:
return (str_or_path, '<String Input>')
if __name__ == '__main__':
s = 'common:\n- &mycolor red\n\nmenu:\n color: *mycolor\n\ncommon:\n- &mycolor blue'
print load_yaml(s)
if __name__ == '_AFDASF':
import wx
a = wx.PySimpleApp()
sys.modules['gui.skin.skintree'].resource_paths = [
path('../../../res')]
skins = list_skins()
if not skins:
sys.exit()
set_active(skins[1])
try:
f = _[2]
f.write('button:\n color: red')
finally:
pass
s = '\ninclude: test.yaml\ninclude: test.yaml\n\nButton:\n font: Arial\n\nbutton:\n Font: Comic Sans MS\n'